package serviceImpl;

import dao.AddDAO;
import dao.GroupDAO;
import dao.UserDAO;
import entity.Group;
import entity.User;
import groupInformation.Relation;
import lombok.SneakyThrows;
import serviceInterface.addInterface;

import java.util.Random;

public class createGroup implements addInterface {
    @SneakyThrows
    @Override
    public boolean add(Group group, User user){
        boolean add_group = false;
        //增加小组和用户
        AddDAO addGroup = new AddDAO();
        UserDAO addUser = new UserDAO();



        if (addGroup.search(group)!=true){
            //小组不存在就创建小组
            int id=(int)(Math.random()*1000)+(int)(Math.random()*100)+(int)(Math.random()*10)+(int)(Math.random()*10000);
            System.out.println("我是随机生成的"+id);
            group.setId(id);
            group.setOwner_id(user.getId());
            group.setOwner(user.getNickname());
            addGroup.insertGroup(group);
            add_group=true;
        }
        else {
            add_group=false;
        }
        return add_group;
    }
}
